package com.simple.gateway.center.domian.application.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.simple.gateway.center.basedata.common.PageUtil;
import com.simple.gateway.center.domian.application.bo.ApplicationInterfaceBO;
import com.simple.gateway.center.domian.application.bo.ApplicationInterfaceMethodBO;
import com.simple.gateway.center.domian.application.bo.ApplicationSystemBO;
import com.simple.gateway.center.domian.application.dto.ApplicationInterfaceDTO;
import com.simple.gateway.center.domian.application.dto.ApplicationInterfaceMethodDTO;
import com.simple.gateway.center.domian.application.dto.ApplicationSystemDTO;
import com.simple.gateway.center.domian.application.param.ApplicationInterfaceMethodParam;
import com.simple.gateway.center.domian.application.param.ApplicationInterfaceParam;
import com.simple.gateway.center.domian.application.param.ApplicationSystemParam;
import com.simple.gateway.center.domian.application.repository.IApplicationManageRepository;
import com.simple.gateway.center.application.IApplicationManageService;
import com.simple.gateway.center.web.param.ApplicationCompositeParam;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目: simple-gateway-core
 *
 * 功能描述:
 *
 * @author: WuChengXing
 *
 * @create: 2023-08-07 17:14
 **/
@Service
public class ApplicationManageServiceImpl implements IApplicationManageService {

    @Resource
    private IApplicationManageRepository registerManageRepository;

    @Override
    public void registerApplication(ApplicationSystemParam param) {
        registerManageRepository.registerApplication(ApplicationSystemBO.param2Bo(param));
    }

    @Override
    public void registerApplicationInterface(ApplicationInterfaceParam param) {
        registerManageRepository.registerApplicationInterface(ApplicationInterfaceBO.param2Bo(param));
    }

    @Override
    public void registerApplicationInterfaceMethod(ApplicationInterfaceMethodParam param) {
        registerManageRepository.registerApplicationInterfaceMethod(ApplicationInterfaceMethodBO.param2Bo(param));
    }

    @Override
    public Page<ApplicationSystemDTO> pageApplicationSystem(ApplicationCompositeParam param) {
        Page<ApplicationSystemBO> applicationSystemBOPage = registerManageRepository.pageApplicationSystem(param);
        List<ApplicationSystemDTO> collect = applicationSystemBOPage.getRecords().stream().map(ApplicationSystemBO::bo2Dto).collect(Collectors.toList());
        return PageUtil.convertPage(applicationSystemBOPage, collect);
    }

    @Override
    public Page<ApplicationInterfaceDTO> pageApplicationInterface(ApplicationCompositeParam param) {
        Page<ApplicationInterfaceBO> applicationInterfaceBOPage = registerManageRepository.pageApplicationInterface(param);
        List<ApplicationInterfaceDTO> collect = applicationInterfaceBOPage.getRecords().stream().map(ApplicationInterfaceBO::bo2Dto).collect(Collectors.toList());
        return PageUtil.convertPage(applicationInterfaceBOPage, collect);
    }

    @Override
    public Page<ApplicationInterfaceMethodDTO> pageApplicationMethod(ApplicationCompositeParam param) {
        Page<ApplicationInterfaceMethodBO> applicationInterfaceMethodBOPage = registerManageRepository.pageApplicationMethod(param);
        List<ApplicationInterfaceMethodDTO> collect = applicationInterfaceMethodBOPage.getRecords().stream().map(ApplicationInterfaceMethodBO::bo2Dto).collect(Collectors.toList());
        return PageUtil.convertPage(applicationInterfaceMethodBOPage, collect);
    }

    @Override
    public List<ApplicationInterfaceMethodDTO> listApplicationMethod(ApplicationCompositeParam param) {
        List<ApplicationInterfaceMethodBO> applicationInterfaceMethodBOS = registerManageRepository.queryApplicationInterfaceMethodList(param.getSystemId(), param.getInterfaceId());
        return applicationInterfaceMethodBOS.stream().map(ApplicationInterfaceMethodBO::bo2Dto).collect(Collectors.toList());
    }
}
